export default {
	baseURL: '',
	get(url,params){
		if(params){
			url+='?'
			Object.keys(params).forEach(v=>{
				url+=`${v}=${params[v]}&`
			})
			url = url.slice(0,-1)
		}
		return fetch(this.baseURL+url,{headers: { token: localStorage.token||'' }}).then(_ => _.json()).then(_ => {
			if(_.code === 403){
				vm.$router.push('/login')
				vm.$message.error('请重新登录！')
				localStorage.clear()
			}
			return _
		})
	},
	post(url, body, isJson = true){
		var token = init()
		var option = {
			method: 'POST',
			headers: {'Content-Type': 'application/json'},
			body: isJson ? JSON.stringify(body) : body
		}
		if(token){
			option.headers.token = token
		}
		return fetch(this.baseURL+url,option).then(_ => _.json()).then(_ => _)
	}
}